local skel = fk.CreateSkill {
  name = "emo__duanren",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__duanren"] = "断刃",
  [":emo__duanren"] = "锁定技，每当你造成伤害后，你重铸受伤角色一种类型所有牌，若未重铸牌，你本回合至其距离为1。",
  ["#emo__duanren-choice"] = "断刃：令 %src 重铸一种类型所有牌。",
}

skel:addEffect(fk.Damage, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and not data.to.dead
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = room:askToChoice(player, { choices = {"basic", "equip", "trick"}, skill_name = skel.name,
    prompt = "#emo__duanren-choice:"..data.to.id})
    local cards = table.filter(data.to:getCardIds("he"), function (id) return Fk:getCardById(id):getTypeString() == choice end)
    if #cards > 0 then
      room:recastCard(cards, data.to, skel.name)
    else
      room:addTableMark(player, "emo__duanren-turn", data.to.id)
    end
  end,
})

skel:addEffect("distance", {
  fixed_func = function(self, from, to)
    if from and to and from:hasSkill(skel.name) and table.contains(from:getTableMark("emo__duanren-turn"), to.id) then
      return 1
    end
  end,
})

return skel
